package com.spa.modules.base.service.impl;


import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.spa.common.api.vo.Result;
import com.spa.common.utils.oConvertUtils;
import com.spa.modules.base.entity.SysLog;
import com.spa.modules.base.mapper.SysLogMapper;
import com.spa.modules.base.service.SysLogService;

/**
 * 描述: 
 * author: P0081447
 * date: 2022-03-27 22:19:51
 */
@Service
public class SysLogServiceImpl implements SysLogService {

    @Autowired
	private SysLogMapper sysLogMapper;
    
	/**
	 * 添加
	 *
	 * @return
	 */
	@Transactional
	public Result<?> insert(SysLog sysLog) {
		sysLogMapper.insert(sysLog);
	    return Result.resultOK("添加成功！");
	}
	
	/**
	 * 分页列表查询
	 *
	 * @param pageSize
	 * @return
	 */
	public Result<Object> queryPageList(HttpServletRequest req, Integer pageNo, Integer pageSize){
		Page<SysLog> page= new Page<>(pageNo, pageSize);
	    LambdaQueryWrapper<SysLog> queryWrapper = new LambdaQueryWrapper<>();
	    String logType = req.getParameter("logType");
	    if(oConvertUtils.isNotEmpty(logType)){
	    	queryWrapper.eq(SysLog::getLogType, logType);
	    }
	    
	    String[] createTime = req.getParameterValues("createTime[]");
	    
	    if(oConvertUtils.isNotEmpty(createTime)) {
	    	queryWrapper.ge(SysLog::getCreateTime, createTime[0]);
		    queryWrapper.le(SysLog::getCreateTime, createTime[1]);
	    }
		queryWrapper.orderByDesc(SysLog::getCreateTime);
	    
	    Page<SysLog> articlePage = sysLogMapper.selectPage(page, queryWrapper);
	    List<SysLog> records = articlePage.getRecords();
	    return Result.resultOK(records);
	}
	
}